#ifndef VENUS_RAY_MARCHING_VOLUME_BUFFER_H
#define VENUS_RAY_MARCHING_VOLUME_BUFFER_H

#include "graphics/opengl.h"
#include "graphics/framebuffer_object.h"
#include "graphics/program_cg.h"

namespace venus {
class VolumeBuffer {
public:
  enum BlendMode { BLEND_NONE = 0, BLEND_ADDITIVE };
  VolumeBuffer(GLint format, int width, int height, int depth, int banks);
  ~VolumeBuffer();
  void Bind() { fbo_->Bind(); }
  void Unbind() { fbo_->Disable(); }
  void SetData(float *data, int bank=0);
  void SetWrapMode(GLint mode, int bank=0);
  void SetFiltering(GLint mode, int bank=0);
  void RunProgram(ProgramCG *fprog, int bank=0);

  void set_blend_mode(BlendMode mode) { blend_mode_ = mode; }
  const FramebufferObject *fbo() const { return fbo_; }
  GLuint texture(int bank = 0) const { return textures_[bank]; }
  int width() const { return width_; }
  int height() const { return height_; }
  int depth() const { return depth_; }
private:
  GLuint Create3dTexture(GLint internalformat, int w, int h, int d);
  void DrawSlice(float z);
private:
  int width_, height_, depth_;
  int max_banks_;
  int banks_;
  BlendMode blend_mode_;
  FramebufferObject *fbo_;
  GLuint *textures_;
};
} // namespace venus

#endif // VENUS_RAY_MARCHING_VOLUME_BUFFER_H
